﻿using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lamex.mIE.Calculate
{
    public class LGC_VAL_BOM_D44
    {
        public static DataTable LGC_VAL_BOM_D44_VALUE(string DWG_No, string Part_No, string Process_Code, string WORKTIME_LOGIC_CODE, DataTable dtBOM)
        {
            string errorMsg = DWG_No + Part_No + Process_Code;
            try
            {
                //适用物料表
                DataTable dtBom_NECESSARY = Common.GetCommon.GetBOM_NECESSARY();
                //BOM表与适用物料表的交集
                DataTable dtcontrast = new DataTable();
                dtcontrast = Common.GetBOM_Logic.DataTableContrast(dtBOM.Select("MATERIAL_NO='" + Part_No + "'").Length > 0 ?
                    dtBOM.Select("MATERIAL_NO='" + Part_No + "'").CopyToDataTable() : null,
                    dtBom_NECESSARY.Select("Operation_Name='柜桶类型'").CopyToDataTable());
                //获取该工序的所有特征名称
                // DataTable dtFeature_Name = Common.GetCommon.GetFEATURE_NAME(Process_Code);


                DataTable dtFeature_List = Common.GetTable.GetTable_Feature();

                //for (int i = 0; i < dtFeature_Name.Rows.Count; i++)
                //{
                DataRow dr = dtFeature_List.NewRow();
                dr["DWG_NO"] = DWG_No;
                dr["PART_NO"] = Part_No;
                dr["PROCESS_CODE"] = Process_Code;
                dr["FEATURE_NAME"] = "D44_抽屉数量";
                dr["FEAT_VALUE"] = Common.GetBOM_Logic.D44_V(Part_No, dtBOM);
                dr["LABOR_VALUE"] = Calculate.LGC_TIM_VTA.LGC_TIM_VTA_VALUE(DWG_No, Part_No, "D44_抽屉数量", "", Convert.ToDouble(dr["FEAT_VALUE"]));//根据特征定义表工时字段计算
                dr["UPDATE_TIME"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                dr["UPDATE_USER"] = Lamex.Common.Loginer.CurrentUser.AccountName;
                dtFeature_List.Rows.Add(dr);
                // }
                if (dtcontrast.Rows.Count > 0)
                {
                    DataRow dr1 = dtFeature_List.NewRow();
                    dr1["DWG_NO"] = DWG_No;
                    dr1["PART_NO"] = Part_No;
                    dr1["PROCESS_CODE"] = Process_Code;
                    dr1["FEATURE_NAME"] = "D44_柜桶_胶抽";
                    dr1["FEAT_VALUE"] = Common.GetBOM_Logic.D44_V(Part_No, dtBOM);
                    dr1["LABOR_VALUE"] = Calculate.LGC_TIM_VTA.LGC_TIM_VTA_VALUE(DWG_No, Part_No, "D44_柜桶_胶抽", "", Convert.ToDouble(dr["FEAT_VALUE"]));//根据特征定义表工时字段计算
                    dr1["UPDATE_TIME"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                    dr1["UPDATE_USER"] = Lamex.Common.Loginer.CurrentUser.AccountName;
                    dtFeature_List.Rows.Add(dr1);
                }
                else
                {
                    DataRow dr2 = dtFeature_List.NewRow();
                    dr2["DWG_NO"] = DWG_No;
                    dr2["PART_NO"] = Part_No;
                    dr2["PROCESS_CODE"] = Process_Code;
                    dr2["FEATURE_NAME"] = "D44_柜桶_木抽";
                    dr2["FEAT_VALUE"] = Common.GetBOM_Logic.D44_V(Part_No, dtBOM);
                    dr2["LABOR_VALUE"] = Calculate.LGC_TIM_VTA.LGC_TIM_VTA_VALUE(DWG_No, Part_No, "D44_柜桶_木抽", "", Convert.ToDouble(dr["FEAT_VALUE"]));//根据特征定义表工时字段计算
                    dr2["UPDATE_TIME"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                    dr2["UPDATE_USER"] = Lamex.Common.Loginer.CurrentUser.AccountName;
                    dtFeature_List.Rows.Add(dr2);
                }

                return dtFeature_List;
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(errorMsg + ex.Message);
                return null;
            }
        }
    }
}
